<?php

namespace app\admin\controller;

use app\admin\model\Admin;
use auth\Auth;
use think\facade\View;

class Login
{
    private $cache_model, $config;


    public function __construct()
    {
        $this->setSysPath();
    }


    /**
     * 登录页面及验证接口
     * @author admin
     * @date 2019-08-08
     */

    public function index()
    {
        try {
            if (request()->isPost()) {
                $u_name = input("post.username", "", "trim");
                $u_pwd = input("post.passwd", "", "trim");
                $code = input("post.code", "", "trim");
                $result = Auth::authenticate($u_name, $u_pwd, $code);
                return json($result);
            } else {
                return View::fetch();
            }
        } catch (\Exception $e) {
            return ['code' => 99999, 'msg' => $e->getMessage()];
        }
    }

    /**
     * 设置后台入口别名
     * @author admin
     * @date 2018-03-17
     */
    public function setSysPath()
    {
        $sys_path = config("admin.adminPath");
        if ($sys_path) {
            define("SYS_PATH", config("admin.adminPath"));
        } else {
            define("SYS_PATH", "admin");
        }
    }


    /**
     * 设置后台入口别名
     * @author admin
     * @date 2018-03-17
     */
    public function setAgentPath()
    {
        $sys_path = config("admin.adminPath");
        if ($sys_path) {
            define("SYS_PATH", config("admin.adminPath"));
        } else {
            define("SYS_PATH", "admin");
        }
    }
    /**
     * 验证码
     * @author 四*川*挚*梦*科技有*限公司
     * @date 2018-03-18
     */
    public function verify()
    {
        return captcha();
    }


}